// subpkg_worker/report/report.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    startTime:'',
    endTime:'',
    moduleList:[],
    countList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var date = new Date()
    var year = date.getFullYear()
    var month = date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1
    var day = date.getDate() < 10?'0'+date.getDate():date.getDate()
    var endTime = `${year}-${month}-${day}`
    var date1 = new Date(date.getTime()-183*24*60*60*1000)
    var year1 = date1.getFullYear()
    var month1 = date1.getMonth()+1<10?'0'+(date1.getMonth()+1):date1.getMonth()+1
    var day1 = date1.getDate() < 10?'0'+date1.getDate():date1.getDate()
    var startTime = `${year1}-${month1}-${day1}`
    this.setData({
      startTime:startTime,
      endTime:endTime
    })
    wx.request({
      url: 'https://zhixiao.site:8080/api-log/query-top-logs',
      data:{
        careHomeName:wx.getStorageSync('beadhouse'),
        startTime:startTime,
        endTime:endTime
      },
      success:(res)=>{
        console.log(res)
        var report = res.data.data
        var moduleList = []
        var countList = []

        for(var i in report){
          moduleList.push(i)
          countList.push(report[i])
        }
        moduleList.sort(function(a,b){
          return b - a
        })
        countList.sort(function(a,b){
          return b - a
        })
        this.setData({
          moduleList:moduleList,
          countList:countList
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})